From 6e05b3b04216df34facf60c400b37cc2a3d16d04 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 4 May 2015 19:26:21 +0200 Subject: [PATCH] Also escape spaces in shell_escape --- src/cargo/util/shell_escape.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cargo/util/shell_escape.rs b/src/cargo/util/shell_escape.rs index d02c1737f..39fb603bd 100644 --- a/src/cargo/util/shell_escape.rs +++ b/src/cargo/util/shell_escape.rs @@ -10,9 +10,10 @@ use std::borrow::Cow; -static SHELL_SPECIAL: &'static str = r#"\$'"`!"#; +static SHELL_SPECIAL: &'static str = r#" \$'"`!"#; -/// Escape characters that may have special meaning in a shell. +/// Escape characters that may have special meaning in a shell, +/// including spaces. pub fn shell_escape(s: Cow) -> Cow { let escape_char = '\\'; // check if string needs to be escaped @@ -32,9 +33,11 @@ pub fn shell_escape(s: Cow) -> Cow { #[test] fn test_shell_escape() { - assert_eq!(shell_escape("--aaa=bbb ccc".into()), "--aaa=bbb ccc"); + assert_eq!(shell_escape("--aaa=bbb-ccc".into()), "--aaa=bbb-ccc"); + assert_eq!(shell_escape("linker=gcc -L/foo -Wl,bar".into()), + r#"linker=gcc\ -L/foo\ -Wl,bar"#); assert_eq!(shell_escape(r#"--features="default""#.into()), r#"--features=\"default\""#); - assert_eq!(shell_escape(r#"'!\$` \\ \n"#.into()), - r#"\'\!\\\$\` \\\\ \\n"#); + assert_eq!(shell_escape(r#"'!\$`\\\n "#.into()), + r#"\'\!\\\$\`\\\\\\n\ "#); } -- 2.30.2